package io.github.talelin.latticy.common.configuration;

import io.github.talelin.autoconfigure.configuration.LinCmsProperties;
import io.github.talelin.latticy.common.util.JwtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName：OmsConfiguration
 * @Author: ljj
 * @Date: 2022/5/31 11:08
 */
@Configuration
public class OmsConfiguration {
    @Autowired
    private LinCmsProperties properties;

    @Bean
    public JwtService jwtser() {
        String secret = properties.getTokenSecret();
        Long accessExpire = properties.getTokenAccessExpire();
        Long refreshExpire = properties.getTokenRefreshExpire();
        if (accessExpire == null) {
            accessExpire = 3600L;
        }

        if (refreshExpire == null) {
            refreshExpire = 2592000L;
        }

        return new JwtService(secret, accessExpire, refreshExpire);
    }
}

